﻿/// <reference path="TurboBase.js" />
/// <reference path="../General/General.js" />
/// <reference path="../General/Elements.js" />
/// <reference path="../General/Events/Events.js" />
/// <reference path="../General/Ajax.js" />
/// <reference path="FieldBinding.js" />








function $GetObject(id)
{
	var t = document.getElementById(id);
	if (t != null)
	{
		if (t.get_Object != null)
			return t.get_Object();
	}
	return null;
}

TA.Turbo.Common.StateFieldClientIdPostfix = "_";
TA.Turbo.Common.StateFieldUniqueIdPostfix = "$";
TA.Turbo.Common.ClientIdSeparator = "_";
TA.Turbo.Common.UniqueIdSeparator = "$";

TA.Turbo.Common.GetState = function GetState(control)
{
	if (control == null)
		Throw("Argument can not be null: control.");

	var se = document.getElementById(control.id + TA.Turbo.Common.StateFieldClientIdPostfix);
	if (se == null)
		return new Object();

	if (se.state == null)
		se.state = eval("(" + se.value + ")");

	return se.state;
}

TA.Turbo.Common.GetPropertyShortName = function GetPropertyShortName(control, propertyName)
{
	return control.get_Object()._propertyDefinitions[propertyName]._shortName;
}
TA.Turbo.Common.GetPropertyNameByShort = function GetPropertyNameByShort(control, shortName)
{
	return control.get_Object()._propertyShortNames[shortName]._name;
}











TA.Turbo.Common.GetControlServerName = function GetControlServerName(control)
{
	if (control._serverName != null)
		return control._serverName;
	if (control.name != null)
		return control.name;
	return control.getAttribute("name");
}
TA.Turbo.Common.GetControlServerId = function GetControlServerId(control)
{
	if (control._serverId != null)
		return control._serverId;
	if (control.id != null)
		return control.id;
	return control.getAttribute("id");
}
TA.Turbo.Common.GetControlClientName = function GetControlClientName(control)
{
	if (control.name != null)
		return control.name;
	return control.getAttribute("name");
}
TA.Turbo.Common.GetControlClientId = function GetControlClientId(control)
{
	if (control.id != null)
		return control.id;
	return control.getAttribute("id");
}





































TA.Turbo.Common.Init_CreateHidden = function Init_CreateHidden(name, value)
{
	var ctl = document.createElement("input");
	ctl.type = "hidden";
	ctl.id = name;
	ctl.name = name;
	ctl.value = value;
	theForm.appendChild(ctl);
}







var theForm = null;
TA.Turbo.Common.Init = function Init(formName, appRootUrl)
{
	theForm = document.forms[formName];
	TA.Turbo.Common.AppRootUrl = appRootUrl;

	// create asp.net hidden fields
	if (theForm["__T"] == null)
		TA.Turbo.Common.Init_CreateHidden("__T");
	if (theForm["__N"] == null)
		TA.Turbo.Common.Init_CreateHidden("__N");
	if (theForm["__A"] == null)
		TA.Turbo.Common.Init_CreateHidden("__A");
}
